package com.estar.app.business.checkDangerous;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.URLDecoder;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.estar.app.appsrvyyabx.mobile.domain.DataVO;
import com.estar.app.business.mobileLogin.controller.MobileServlet;
import com.thoughtworks.xstream.XStream;


@Controller("checkDangerousServlet")
@Scope("prototype")
public class CheckDangerousServlet {
	
	private static final Logger logger = Logger.getLogger(CheckDangerousServlet.class);
	
	@RequestMapping(params = "findDangerTimes")
	public void findDangerTimes(HttpServletRequest request,HttpServletResponse response){
		DataVO dataReturnVO = new DataVO();
		DataVO dataSendVO = new DataVO();
		InputStreamReader isr = null;
		BufferedReader in =null;
		
		
		try {
			isr = new InputStreamReader(request.getInputStream(), "UTF-8");
			in = new BufferedReader(isr);
			StringBuffer inStr = new StringBuffer("");
			String inputLine;
			while ((inputLine = in.readLine()) != null) {
				inStr.append(inputLine);
				inStr.append("\n");
			}
			in.close();
			if (inStr == null || "".equals(new String(inStr))) {
				dataReturnVO.setResultCde("0");
				dataReturnVO.setMessage("接收的数据为空");
			} else {
					
				String sendXml = URLDecoder.decode(inStr.toString(), "UTF-8");	// 转码
				
				dataSendVO = (DataVO) new XStream().fromXML(sendXml);
				
				// 用户相关
				if (dataSendVO.getAction().trim().equals("user")){		
					//密码修改
					if(dataSendVO.getMethod().trim().equals("changePasswork")){
//						dataReturnVO= respCheckUtil.changePasswork(dataSendVO);
					}
				}
			}
		} catch (Exception e) {
			dataReturnVO.setResultCde("0");
			dataReturnVO.setMessage("系统错误。");
			logger.error("系统异常：",e);
		} finally {		// 返回数据
			String outStr = new XStream().toXML(dataReturnVO);
			
			try {
				if(in!=null){
					in.close();
				}
				if(isr!=null){
					isr.close();
				}
				
				response.setContentType("text/html; charset=UTF-8");
				PrintWriter write = response.getWriter();
				write.write(outStr);
				write.close();
			} catch (Exception ex) {
				logger.error("系统异常：",ex);
			}
		}
	}
}
